package com.top.ruizhong.main.host

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentStatePagerAdapter
import com.blankj.utilcode.util.ColorUtils
import com.blankj.utilcode.util.LogUtils
import com.google.android.material.tabs.TabLayout
import com.module.lemlin.base.BaseAbstractActivity
import com.top.ruizhong.R
import kotlinx.android.synthetic.main.activity_main_order.*

class MainOrderActivity : BaseAbstractActivity() {

    companion object {
        fun open(activity: Activity) {
            val intent = Intent(activity, MainOrderActivity::class.java)
            activity.startActivity(intent)
        }

        private val tabs: MutableList<String> = mutableListOf(
            "全部订单", "待支付", "待使用", "已使用"
        )
    }

    override val layoutResId: Int
        get() = R.layout.activity_main_order

    override fun stateBar(): StatusBar {
        return StatusBar(isLightMode = true, color = R.color.colorWhite, view = flGoodsOrderBar)
    }

    override fun initView() {
        ivGoodsOrderBack.setOnClickListener { this.finish() }
        //tab&vp
        tabGoodsOrderStatus.apply {
            addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
                override fun onTabReselected(tab: TabLayout.Tab?) = Unit

                override fun onTabUnselected(tab: TabLayout.Tab?) {
                    tab?.customView = null
                }

                override fun onTabSelected(tab: TabLayout.Tab?) {
                    val text: TextView = TextView(context).apply {
                        setTextColor(ColorUtils.getColor(R.color.colorMain))
                        textSize = 16f
                        gravity = Gravity.CENTER
                        paint.isFakeBoldText = true
                    }
                    text.text = tab?.text
                    tab?.customView = text
                }
            })
        }.setupWithViewPager(vpGoodsOrderBody.apply {
            adapter = object : FragmentStatePagerAdapter(
                supportFragmentManager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT
            ) {

                override fun getItem(position: Int): Fragment =
                    MainOrderFragment.newInstance()

                override fun getCount(): Int = tabs.size

                override fun getPageTitle(position: Int): CharSequence? {
                    return tabs[position]
                }

                override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {}
            }
        })

    }

}